package com.sh.data.engine.domain.normalization.modeldesign.model.model.enums;

import com.sh.data.engine.domain.normalization.modeldesign.model.model.domain.StorageDomain.FieldType;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum Kingbase8FieldTypeEnum {
    TINYINT("smallint", false),
    SMALLINT("smallint", true),
    INT("integer", true),
    BIGINT("bigint", true),

    FLOAT("real", true),
    DOUBLE("double precision", true),
    DECIMAL("numeric(20,10)", true),

    TIMESTAMP("timestamp without time zone", true),

    CHAR("character(255)", true),
    STRING("text", true),
    VARCHAR("character varying(400)", true),

    DATE("date", true),
    BOOLEAN("boolean", true),
    BINARY("bytea", true);

    private final String dbFieldType;
    // 是否对前台用户可见
    private boolean userVisible;

    Kingbase8FieldTypeEnum(String dbFieldType, boolean userVisible) {
        this.dbFieldType = dbFieldType;
        this.userVisible = userVisible;
    }

    public String getDbFieldType() {
        return dbFieldType;
    }

    public static List<FieldType> getAllFieldType() {
        Kingbase8FieldTypeEnum[] values = Kingbase8FieldTypeEnum.values();
        return Arrays.stream(values)
            .filter(i -> i.userVisible)
            .map(i -> new FieldType(i.dbFieldType, i.name()))
            .collect(Collectors.toList());
    }

    /**
     * 主数据字段类型列表
     *
     * @return
     */
    public static List<String> getMdAllFieldType() {
        Kingbase8FieldTypeEnum[] values = Kingbase8FieldTypeEnum.values();
        return Arrays.stream(values).map(i -> i.dbFieldType).collect(Collectors.toList());
    }

}
